﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Core.Business;

namespace TicketManagement.User
{
    public partial class Login : System.Web.UI.Page
    {
        private UserBus userBus;
        private Core.Entity.User user;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["User"] != null)
            {
                try
                {
                    if (user.UserTypeId != 4)
                    {
                        Response.Redirect("/Home/Dashboard.aspx");
                    }
                    else
                    {
                        Response.Redirect("/Home/Index.aspx");
                    }
                }
                catch (Exception ex) { }
            }
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            checkLogin();
        }
        public void checkLogin() {
            userBus = new UserBus();
            user = new Core.Entity.User();
            string login = "sondt@caodangnghesaigon.edu.vn"; //txtLogin.Value.Trim();
            string password = "123456"; //txtPassword.Value.Trim();
            if (txtLogin.Value.Trim() != "")
            {
                login = txtLogin.Value.Trim();
                password = txtPassword.Value.Trim();
            }

            user = userBus.login(login, password);

            if (user != null)
            {
                Session["User"] = user.Id;
                if (user.UserTypeId != 4)
                {
                    Response.Redirect("/Home/Dashboard.aspx");
                }
                else
                {
                    Response.Redirect("/Home/Index.aspx");
                }
            }
            else
            {
                lblMessage.Text = "Username or Password invalid";
            }
        }
    }
}